package com.zy.qudadid.presenter;

import com.zy.qudadid.model.Res;
import com.zy.qudadid.model.User;
import com.zy.qudadid.network.Const;
import com.zy.qudadid.network.Net;
import com.zy.qudadid.presenter.base.BasePresenterImp;
import com.zy.qudadid.ui.view.MyWalletView;
import com.zy.qudadid.utils.UserUtil;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by liuchao on 2017/3/8.
 */

public class MyWalletPresenter extends BasePresenterImp<MyWalletView> {

    public void getInfo(String args){
        Subscription subscription = Net.getService()
                .getWalletMoney(args)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(Res res) {
                        if(res.code == Const.OK){
                            UserUtil userUtil = new UserUtil(view.getContext());
                            User user = userUtil.getUser();
                            user.account = res.datas.toString();
                            userUtil.putUser(user);
                            view.getInfoSuccess();
                        }else{
                            view.getInfoError(res.message);
                        }
                    }
                });
        addSubscription(subscription);
    }

}
